<template>
  <div class="container scopClass" v-if="List.length > 0">
    <el-tabs
      v-model="activeName"
      type="border-card"
      style="margin-top: 20px"
      @tab-click="handleClick"
    >
      <el-tab-pane
        :label="item.templateName"
        :name="item.templateName"
        v-for="(item, index) in List"
        :key="index"
      >
        <!-- <el-row style="margin: 20px 0">
          <el-col :span="7">
            <el-input
              style="border-radius: 0 5px 5px 0; width: 300px"
              placeholder="请输入关键词"
              v-model.trim="searchName1"
            >
              <i slot="prefix" class="el-input__icon el-icon-search"></i>
              <el-button slot="append" @click="handleSearch1">搜索</el-button>
            </el-input>
          </el-col>
          <el-button
            type="primary"
            @click="newAdd"
            style="float: right; margin-right: 10px"
            >新增</el-button
          >
        </el-row> -->
        <el-table
          :data="tableData"
          border
          ref="multipleTable"
          header-cell-class-name="table-header"
        >
          <el-table-column prop="" sortable label="标识分类" >
            <template slot-scope="scope">
              <span v-if="scope.row.fromFactoryName !== null">{{scope.row.fromFactoryName}}</span>
              <span v-else>{{scope.row.factoryName}}</span>
            </template>
          </el-table-column>
          <!-- <el-table-column prop="factoryName" sortable label="标识分类" ></el-table-column> -->
          <el-table-column prop="inventoryType" sortable label="产品大类"></el-table-column>
          <el-table-column prop="breedName" sortable label="名称"></el-table-column>
          <el-table-column prop="loadingQuantity" sortable label="装量"></el-table-column>
          <el-table-column prop="loadingUnits" sortable label="包装"></el-table-column>
          <el-table-column prop="createTime" sortable label="添加修改时间"></el-table-column>
          
          <el-table-column label="操作" width="150" align="center">
            <template slot-scope="scope">
              <el-button
                type="text"
                @click="handleEdit(scope.$index, scope.row)"
                >编辑</el-button
              >
            </template>
          </el-table-column>
        </el-table>
        <el-pagination
          layout="total, prev, pager, next, jumper"
          :page-size="pagesize1"
          @current-change="handleCurrentChange1"
          :total="total1"
          :current-page.sync="currentPage1"
          style="margin-top: 20px"
        ></el-pagination>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
import { materialBreed_list, materialBreed_delete } from "@/request/api";
import {
  materials_import,
  template_findByCompanyId as templateFindByCompanyId,
  materialBreed_findByLis as materialBreedFindByLis,
} from "@/request/manageapi";
import uploadFile from "../../../common/uploadfile";
export default {
  props: ["activeName1"],
  components: {
    uploadFile,
  },
  data() {
    return {
      tableData: [],
      total1: 0,
      currentPage1: 1,
      pagesize1: 10,
      activeName: "",
      searchName1: "",
      List: [],
    };
  },
  async created() {
    await this.init();
    await this.materialBreedFindByLis();
    // var data = JSON.stringify(this.$store.state.wl);
    // var a = "新增";
    // var b = "编辑";
  },
  mounted() {},
  destroyed: function () {
    this.$store.commit("setStorName", "");
  },
  methods: {
    // 调用接口
    init() {
      let companyId = this.activeName1;
      return new Promise((resolve, reject) => {
        templateFindByCompanyId(`?companyId=${companyId}&&isNew=1`)
          .then((res) => {
            this.List = res.data;
            if (this.List.length > 0) {
              this.activeName = this.List[0].templateName;
            }
            resolve(res);
          })
          .catch((err) => {
            reject(err);
          });
      });
    },
    materialBreedFindByLis() {
      let companyId = this.activeName1;
      let materialType = "配方颗粒";
      let inventoryType = this.activeName;
      let page = this.currentPage1;
      let data = {
        companyId,
        materialType,
        inventoryType,
        page,
      };
      return new Promise((resolve, reject) => {
        materialBreedFindByLis(data).then((res) => {
          if (res.code == 200) {
            this.total1 = res.total
            let tableData = res.rows;
            this.tableData = JSON.parse(JSON.stringify(tableData));
          }
          console.log(res);
          resolve(res);
        });
      });
    },
    handleSearch1() {},
    // tabs
    async handleClick(tab, event) {
      this.currentPage1 = 1
      await this.materialBreedFindByLis();
    },
    // 编辑
    handleEdit(index, row) {
      this.$router.push({
        name:"managerecordAdd",
        params: {
            data: row
          }
      });
    },
    // 分页事件
    async handleCurrentChange1(val) {
      this.currentPage1 = val;
      await this.materialBreedFindByLis();
    },
  },
  watch: {
    activeName1: {
      async handler(newVal, oldVal) {
        this.activeName1 = newVal;
        await this.init();
        await this.materialBreedFindByLis();
      },
      deep: true,
    },
  },
};
</script>

<style lang="less" scoped>
// 深度作用器
/deep/.upload-daoru {
  .el-upload {
    border: none;
    width: auto;
    height: auto;
    border-radius: 0;
    float: right;
    margin-right: 10px;
  }
}
.el-col {
  margin-bottom: 0;
}
/* .scopClass .el-table{ margin-top: 20px;} */
.el-pagination {
  text-align: center;
}
/* 
.el-select .el-input {
width: 130px;
}
.input-with-select .el-input-group__prepend {
background-color: #fff;
}
.el-input--small .el-input__inner{
    border-radius: 5px 0 0 5px !important;
    border-right: none;
} */
</style>
